package org.winFame.dispy;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.scene.control.Hyperlink;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.web.WebView;
import org.App;
import org.tools.SdData;
import org.winFame.FlowPaneFrameWork;

public class PaneBlockframeWork {
    public Pane init(String urls,String title,String download) {
        Pane pane = new Pane ();
        pane.setStyle("-fx-background-color: #f3f3f3;");
        pane.setPrefWidth(300);
        pane.setPrefHeight(480);

        WebView webView = new WebView();
        webView.setDisable(true);
        webView.setPrefWidth(300);
        webView.setPrefHeight(400);
        webView.setStyle("-fx-background-color: #6c838c;-fx-fill: #61b8e7");
        webView.getEngine().loadContent("<style>*{margin: 0 auto;padding: 0;overflow: hidden;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;}</style><img src='"+urls+"' width=100% />");

        Hyperlink titleLink = new Hyperlink();
        titleLink.setText(title);
        titleLink.setPrefWidth(100);
        titleLink.setLayoutX(20);
        titleLink.setDisable(false);
        titleLink.setLayoutY(425);
        titleLink.setDisable(true);
        titleLink.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
//                ThreadGetData.pageIndex++;
//                FlowPaneFrameWork.flowPane.getChildren().clear();
//                Thread t = new Thread(new ThreadGetData());
//                t.start();
                App.downLen++;
            }
        });
        Hyperlink addList = new Hyperlink();
        addList.setText("下载模型");
        addList.setLayoutX(200);
        addList.setLayoutY(425);
        if(App.downLoadPath.equals("")){
            addList.setDisable(true);
        }else {
            addList.setDisable(false);
        }
        addList.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                addList.setDisable(true);
                App.downLen++;
                App.stage.setTitle("www.snailcatmall.com - SD模型批量下载工具"+" 下载队列： "+App.downLen);
               Thread t = new Thread(new Runnable() {
                   @Override
                   public void run() {
                       int code = SdData.downLoad_Win(download,"C:\\downloads\\");
                       Platform.runLater(new Runnable() {
                           @Override
                           public void run() {
                               if(code==0){
                                   addList.setDisable(false);
                               }else {
                                   addList.setDisable(false);
                               }
                           }
                       });
                   }
               });
                t.start();
            }
        });


        pane.getChildren().addAll(
                webView,
                titleLink,
                addList
        );
        return pane;
    }
}
